<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="${baes }/static/hui/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="${baes }/static/hui/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="${baes }/static/hui/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="${baes }/static/hui/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="${baes }/static/hui/static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>添加领取人</title>
<link href="lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="page-container">
	<form class="form form-horizontal" id="form-article-add">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">充值卡<b style="color: red;font-size: 16px;">*</b>:</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text newmer" value="" placeholder="请输入充值卡开始的卡号" id="" name="sequenceBegin">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">&nbsp;</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text newmer" value="" placeholder="请输入充值卡结束的卡号" id="" name="sequenceEnd">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">面额<b style="color: red;font-size: 16px;">*</b>:</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text newmer" value="" placeholder="充值卡面额" id="" name="facePrice">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">数量<b style="color: red;font-size: 16px;">*</b>:</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text newmer" value="" placeholder="数量" id="" name="receiveCount">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">领取人<b style="color: red;font-size: 16px;">*</b>:</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text newmer" value="" placeholder="请输入领取人的名字" id="" name="receiveName">
			</div>
		</div>
		
		
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
				<button id="submitButton" class="btn btn-primary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 保存并领取</button>
				<button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
			</div>
		</div>
	</form>
</div>
 

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="${baes }/static/hui/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${baes }/static/hui/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="${baes }/static/hui/static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="${baes }/static/hui/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer /作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="${baes }/static/hui/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="${baes }/static/hui/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="${baes }/static/hui/lib/jquery.validation/1.14.0/messages_zh.js"></script> 
<script type="text/javascript" src="${baes }/static/hui/lib/webuploader/0.1.5/webuploader.min.js"></script> 
<script type="text/javascript">
$(document).ready(function(){
	
	$("#submitButton").click(function(){
        
        var sequenceBegin = $("input[name=sequenceBegin]").val();//充值卡号1
        var sequenceEnd   = $("input[name=sequenceEnd]").val();//充值卡号
        var receiveCount  = $("input[name=receiveCount]").val();//卡数量
        var facePrice     = $("input[name=facePrice]").val();//面额
        var receiveName     = $("input[name=receiveName]").val();//领卡人
        
        var isCheck = true;
        $('.newmer').each(function(){
            if ($(this).val()=='') {
                layer.msg("*为必填字段,不得为空");
                isCheck = false;
            }
        });
        if(sequenceBegin.length != 16 && sequenceBegin.length != 18){
            isCheck = false;
        	layer.msg("您输入的卡号有误!");
        }
        if(sequenceEnd.length != 16 && sequenceEnd.length != 18){
            isCheck = false;
        	layer.msg("您输入的卡号有误!");
        }
        if(sequenceEnd<sequenceBegin){
        	isCheck = false;
        	layer.msg("您输入的卡号区间有误!");
        }
        //.substring(start,stop)
        //alert(parseInt(sequenceBegin)-parseInt(sequenceEnd));
      
        var num1 = parseInt(sequenceEnd.substring(9,sequenceEnd.length));
        var num2 = parseInt(sequenceBegin.substring(9,sequenceBegin.length));
        if((num1-num2+1)!=receiveCount){
        	isCheck = false;
        	layer.msg("您输入的卡号数量有误!");
        }
        if($.isNumeric(facePrice)==false){
            layer.msg("请输入正确的面额");
            return false;
        }
        if(isCheck==true){
        	$.ajax({
                url:"${pageContext.request.contextPath}/admin/addReceiver",
                type:'post',
                dataType:'json',
                data:{'sequenceBegin':sequenceBegin,'sequenceEnd':sequenceEnd,
                	'receiveCount':receiveCount,'facePrice':facePrice,
                	'receiveName':receiveName},
                success:function(res)
                {
                    if(res.code == '1'){
                        layer.msg(res.msg, {icon: 1});
                    }else{
                        layer.msg(res.msg, {icon: 5});
                    }
                    //页面跳转
                    location.href="${base}/admin/receiveAll";
                    
                    $("#submitButton").show();
                    $("#submitShow").hide();
                    $("#orderlist_form")[0].reset();
                    
                }
            });
            return false;
        }
        
    });
});
</script>
</body>
</html>